package com.huiquan.foundation.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huiquan.analysis.dao.UserDao;
import com.huiquan.foundation.domain.Pagination;
import com.huiquan.framework.base.BaseService;

@Service
public class PaginationService extends BaseService {
	@Autowired
	private UserDao userDao;
	/**
	 * 平均分页
	 * @param list
	 * @return
	 */
	public List<Pagination> averagePaging(List<Pagination> list, long role){
		//根据权限查询拥有该权限的uid
		List<String> uids =  userDao.retrieveUsersByRole(role);
		if(uids == null || uids.size() == 0){
			return null;
		}else{
			int j = 1;
			long pageNo = 1;
			for(int i=0;i<list.size();i++){
				if(j<=uids.size()){
					list.get(i).setOwnerId(Long.parseLong(uids.get(j-1)));
					list.get(i).setPageNo(pageNo);
					j++;
					if(j>uids.size()){
						j=1;
						pageNo++;
					}
				}
			}
			return list;
		}
	}
	
}
